Skip to content

Conversation

@arvi18
Copy link

@arvi18 arvi18 commented Apr 28, 2025

Additional info will be added in follow-ups.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@meisterT PTAL

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

ping?

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@Yannic I am sorry that I didn't get to this one earlier.

What other metrics do you plan to include here in the future? If it is just the total time, adding it here might be better? https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto;l=955;drc=58eeea17db80cc85d685d9319655f2dc398f063d

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

@meisterT I'd like to include the actions on the critical path and metrics about them (executed locally vs remotely vs in a worker, how long input upload or output download took, ...)

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Is that uploaded to BES like the Bazel profile?

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Yes, it is. That's also how we use it internally.

@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

Warning

Rate limit exceeded

@visz11 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c0c98a2 and bc17e9a.

📒 Files selected for processing (10)
  • src/main/java/com/google/devtools/build/lib/buildeventstream/proto/BUILD (1 hunks)
  • src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto (5 hunks)
  • src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java (2 hunks)
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/AggregatedCriticalPath.java (2 hunks)
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/BUILD (1 hunks)
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/CriticalPathEvent.java (1 hunks)
  • src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java (1 hunks)
  • src/main/protobuf/BUILD (2 hunks)
  • src/main/protobuf/critical_path.proto (1 hunks)
  • src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Oh, great! Let me see if that works for what I had in mind

@arvi18
Copy link
Author

arvi18 commented Apr 28, 2025

Yes, it is. That's also how we use it internally.

I assume we need to modify --remote_build_event_upload=minimal to upload this as well, as that only uploads logs and the profile currently:

https://github.com/bazelbuild/bazel/blob/c9c28a9b4324f1eebbbe2e23f471e0880fabd559/src/main/java/com/google/devtools/build/lib/remote/ByteStreamBuildEventArtifactUploader.java#L222-L236

cc: @coeuvre

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @arvi18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request introduces the critical path to the Build Event Protocol (BEP). It adds a new protobuf definition for CriticalPath, includes it in the BuildEvent message, and publishes a CriticalPathEvent to the event bus. This allows clients to receive information about the total time of the critical path of a build via the BEP.

Highlights

  • Critical Path Proto Definition: A new proto file critical_path.proto is added, defining the CriticalPath message, which includes the total time of the critical path.
  • BEP Integration: The CriticalPath message is integrated into the BuildEvent proto, allowing it to be included in the Build Event Stream.
  • Event Publishing: The AggregatedCriticalPath class now posts a CriticalPathEvent to the event bus, which contains the total time of the critical path. This event is then included in the BEP.
  • Build Tool Changes: The BuildTool class is modified to include the CriticalPathEvent in the list of events posted at the end of a build.

Changelog

Click here to see the changelog
  • src/main/java/com/google/devtools/build/lib/buildeventstream/proto/BUILD
    • Added dependency on //src/main/protobuf:critical_path_proto.
  • src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto
    • Imported src/main/protobuf/critical_path.proto.
    • Added critical_path to the BuildEventId oneof.
    • Added critical_path field to the BuildEvent message.
  • src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
    • Imported com.google.devtools.build.lib.metrics.criticalpath.CriticalPathEvent.
    • Added CriticalPathEvent.BEP_ID to the list of events posted in stopRequest().
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/AggregatedCriticalPath.java
    • Added postEvent() method to post the CriticalPathEvent to the event bus.
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/BUILD
    • Added dependencies for BEP integration and protobuf.
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/CriticalPathEvent.java
    • Created new class CriticalPathEvent to represent the BEP event for the critical path.
  • src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
    • Called criticalPath.postEvent(eventBus) to publish the event.
  • src/main/protobuf/BUILD
    • Added critical_path_proto, critical_path_java_proto, and critical_path_java_proto_srcs targets.
    • Added :critical_path_java_proto_srcs to the filegroup.
  • src/main/protobuf/critical_path.proto
    • Created new proto file critical_path.proto to define the CriticalPath message.
  • src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
    • Added BuildSummaryStatsModule to the runtime builder.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A path so critical,
Its time we must chronicle,
In BEP it shall reside,
With duration as its guide,
A build's tale, now typical.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces the critical path to the Build Event Protocol (BEP). This is a valuable addition for understanding build performance. The changes involve adding a new protobuf definition for critical path data, integrating it into the build process, and exposing it through the BEP. Overall, the changes seem well-structured, but some areas could benefit from further clarification and potential improvements.

Summary of Findings

  • Missing Documentation: The pull request description is minimal. More information about the purpose of the changes, how to use the new feature, and any potential impact on existing functionality would be beneficial.
  • Clarity of 'Next id' Comments: The comments indicating 'Next id' in the protobuf definitions could be more descriptive. It's not immediately clear what these IDs refer to or why they are important.
  • Error Handling: While the code adds functionality for critical path analysis, it's not clear how errors during critical path computation or BEP event posting are handled. Robust error handling is crucial for production systems.

Merge Readiness

The pull request introduces important functionality, but it's not quite ready for merging. The missing documentation and lack of clarity in certain comments should be addressed. Additionally, the error handling aspects need to be carefully reviewed. I am unable to directly approve this pull request, and recommend that it not be merged until these issues are addressed, and that others review and approve this code before merging.

Comment on lines +109 to +114
/**Posts the {@code BEP} event for the critical path on the provided {@link EventBus}. */
public void postEvent(EventBus eventBus) {
Preconditions.checkNotNull(eventBus);

eventBus.post(new CriticalPathEvent(Duration.ofMillis(totalTimeInMs)));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding a try-catch block around the eventBus.post call to handle potential exceptions during event posting. This could prevent the entire build from failing if there's an issue with the event bus.

  /**Posts the {@code BEP} event for the critical path on the provided {@link EventBus}. */
  public void postEvent(EventBus eventBus) {
    Preconditions.checkNotNull(eventBus);
    try {
      eventBus.post(new CriticalPathEvent(Duration.ofMillis(totalTimeInMs)));
    } catch (Exception e) {
      // Log the exception or handle it appropriately.
      System.err.println("Error posting CriticalPathEvent: " + e.getMessage());
    }
  }

@visz11
Copy link
Collaborator

visz11 commented Apr 28, 2025

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Apr 28, 2025

✅ Actions performed

Full review triggered.

@atharvsabdeai
Copy link

atharvsabdeai commented Jul 23, 2025

/refacto-test

@refacto-test
Copy link

refacto-test bot commented Jul 23, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
import java.time.Duration;
import java.util.Collection;

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Information Disclosure Consideration: The CriticalPathEvent exposes detailed timing information (down to nanoseconds) about the build's critical path. While this is low severity, consider if this level of detail is necessary for all users or if access controls should limit this information to authorized users only. In security-sensitive environments, this information could potentially aid in reconnaissance by revealing system bottlenecks or optimization targets.

@atharvsabdeai
Copy link

/refacto-test

@refacto-test
Copy link

refacto-test bot commented Jul 23, 2025

PR already reviewed at the latest commit: bc17e9a.
Please try again with new changes.

@PrathameshD1408
Copy link

/refacto-test

@PrathameshD1408
Copy link

/refacto-test

@refacto-test
Copy link

refacto-test bot commented Sep 18, 2025

Refacto is reviewing this PR. Please wait for the review comments to be posted.

@refacto-test
Copy link

refacto-test bot commented Sep 18, 2025

Code Review: BEP Integration Enhancement

👍 Well Done
Critical Path Tracking

Adding critical path tracking to BEP enables performance analysis and bottleneck identification.

Proper Resource Management

Duration objects are properly constructed with appropriate error handling for time values.

Event Ordering Implementation

BuildEventWithOrderConstraint ensures critical path events post after build completion for reliable sequencing.

📌 Files Processed
  • src/main/protobuf/critical_path.proto
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/CriticalPathEvent.java
  • src/main/protobuf/BUILD
  • src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/AggregatedCriticalPath.java
  • src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
  • src/main/java/com/google/devtools/build/lib/buildeventstream/proto/BUILD
  • src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
  • src/main/java/com/google/devtools/build/lib/metrics/criticalpath/BUILD
  • src/main/java/com/google/devtools/build/lib/runtime/BuildSummaryStatsModule.java
📝 Additional Comments
src/main/java/com/google/devtools/build/lib/metrics/criticalpath/AggregatedCriticalPath.java (1)
Event Failure Handling

The event posting lacks error handling for potential EventBus failures. If the event bus rejects the event or throws an exception, there's no recovery mechanism, potentially causing silent failures in critical path reporting.

Standards:

  • ISO-IEC-25010-Reliability-Fault-Tolerance
  • SRE-Error-Handling
src/main/java/com/google/devtools/build/lib/metrics/criticalpath/CriticalPathEvent.java (4)
Defensive Duration Construction

The duration conversion assumes totalTime is valid without bounds checking. Extremely large durations could cause overflow or precision issues when converting to protobuf Duration, potentially causing incorrect critical path timing reports.

Standards:

  • ISO-IEC-25010-Functional-Correctness-Precision
  • DbC-Precondition
Duration Conversion Optimization

The conversion from Java Duration to protobuf Duration is a common pattern that could benefit from a utility method. Creating a reusable conversion utility would reduce code duplication when more duration conversions are needed in the BEP.

Standards:

  • ISO-IEC-25010-Performance-Efficiency-Maintainability
  • Optimization-Pattern-Code-Reuse
  • Algorithmic-Complexity-Constant-Time
Incomplete Error Handling

The duration conversion lacks error handling for potential negative durations or extreme values. While java.time.Duration handles negative values, the conversion to protobuf Duration should validate input to prevent potential logical errors in the protocol buffer representation.

Standards:

  • Business-Rule-Input-Validation
  • Logic-Verification-Data-Conversion
  • Algorithm-Correctness-Value-Validation
Incomplete Event Ordering

The event is configured to be posted after buildFinished, but there's no guarantee that the critical path computation is complete at that point. Consider adding additional ordering constraints to ensure the critical path data is fully computed before the event is posted.

Standards:

  • Business-Rule-Event-Ordering
  • Logic-Verification-Execution-Flow
  • Algorithm-Correctness-Dependency-Chain
src/main/protobuf/critical_path.proto (3)
Package Naming Consistency

While the package naming is consistent with java_package, consider adding a comment explaining the package structure and naming convention. This improves maintainability by documenting the organizational pattern for future extensions.

Standards:

  • Clean-Code-Naming
  • Maintainability-Quality-Consistency
Commented Code Removal

Commented-out configuration option creates maintenance confusion. Either remove the commented line or add an explanation comment about why it's preserved but disabled to improve code clarity.

Standards:

  • Clean-Code-Comments
  • Maintainability-Quality-Clarity
Uncommented Java Option

The commented-out java_api_version option should be either removed or enabled. Commented configuration options can lead to confusion about which security features are active and may be accidentally enabled in future without proper review.

Standards:

  • CWE-489
  • OWASP-A05

/**Posts the {@code BEP} event for the critical path on the provided {@link EventBus}. */
public void postEvent(EventBus eventBus) {
Preconditions.checkNotNull(eventBus);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Event Validation

The eventBus.post() call lacks null checking for totalTimeInMs which could cause runtime exceptions if the field is uninitialized. This could lead to failure when posting critical path events, potentially breaking the build event protocol integration.

Standards
  • ISO-IEC-25010-Reliability-Fault-Tolerance
  • ISO-IEC-25010-Functional-Correctness-Appropriateness
  • DbC-Precondition

Comment on lines +698 to 701
BuildEventIdUtil.buildToolLogs(),
BuildEventIdUtil.buildMetrics(),
CriticalPathEvent.BEP_ID)));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential Null Reference

Added CriticalPathEvent.BEP_ID reference without null checking could cause NullPointerException if BEP_ID is not properly initialized. This would break the build completion event posting, potentially causing build failures or incomplete build events.

Standards
  • ISO-IEC-25010-Reliability-Fault-Tolerance
  • ISO-IEC-25010-Functional-Correctness-Appropriateness

public void postEvent(EventBus eventBus) {
Preconditions.checkNotNull(eventBus);

eventBus.post(new CriticalPathEvent(Duration.ofMillis(totalTimeInMs)));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Event Registration

The CriticalPathEvent is posted to the eventBus but there's no corresponding registration of the event handler. Without proper registration, the event will be posted but may not be processed by any listeners, causing the critical path information to be lost.

Standards
  • Business-Rule-Event-Handling
  • Logic-Verification-Event-Flow
  • Algorithm-Correctness-Event-Processing

Comment on lines +26 to +32
// Represents the critical path of a build.
message CriticalPath {
// Identifier of a BES event of this type.
message BepId {}

// The total time of the critical path.
google.protobuf.Duration total_time = 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete Documentation

The CriticalPath message lacks comprehensive documentation about its purpose and usage. Adding more detailed comments would improve maintainability by clarifying what critical path represents and how it's calculated.

Standards
  • Clean-Code-Documentation
  • Maintainability-Quality-Documentation

Comment on lines +27 to +32
message CriticalPath {
// Identifier of a BES event of this type.
message BepId {}

// The total time of the critical path.
google.protobuf.Duration total_time = 1;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limited Event Data

The CriticalPath message contains only total_time with no additional information about path components or bottlenecks. This limits extensibility and future analysis capabilities. Consider adding fields for critical path components.

Standards
  • SOLID-OCP
  • Design-Pattern-Extensibility
  • Maintainability-Quality-Evolvability

Comment on lines +23 to +27
CriticalPathEvent(Duration totalTime) {
super(BEP_ID, ImmutableList.of());

this.totalTime = Preconditions.checkNotNull(totalTime);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Limited Constructor Access

CriticalPathEvent constructor has package-private access, limiting reusability from other packages. Consider making it public with appropriate factory methods if this event should be creatable outside its package.

Standards
  • Clean-Code-API-Design
  • SOLID-OCP
  • Maintainability-Quality-Reusability

Comment on lines +110 to +114
public void postEvent(EventBus eventBus) {
Preconditions.checkNotNull(eventBus);

eventBus.post(new CriticalPathEvent(Duration.ofMillis(totalTimeInMs)));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factory Method Missing

Direct instantiation of CriticalPathEvent couples AggregatedCriticalPath to the concrete implementation. Consider adding a factory method in CriticalPathEvent for creating instances, improving maintainability through better abstraction.

Standards
  • Design-Pattern-Factory
  • SOLID-DIP
  • Maintainability-Quality-Coupling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants